﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class MyBook : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Form["lb"] != null)
            {
                Response.Clear();
                //登录
                if (Page.User.Identity.Name == "")
                    Response.Write("尚未登录");
                else
                {
                    if (Request.Form["lb"].ToString() == "delete")
                    {
                        string sBookID = Request.Form["bookid"].ToString();
                        string sUserName = Page.User.Identity.Name;
                        BookManger.deleteBook(sUserName, sBookID);
                    }//end of login if
                    else if (Request.Form["lb"].ToString() == "add")
                    {
                        string sBookID = Request.Form["bookid"].ToString();
                        string sUserName = Page.User.Identity.Name;
                        int iRows=BookManger.addBook(sUserName, sBookID);
                        if(iRows>0)
                            Response.Write(iRows.ToString()+"本书成功加入个人书架");
                        else
                            Response.Write("加入书架失败，可能已在书架中");
                    }
                }
                Response.End();
            }//end of check
            //没有参数的时候检查是否已经登录，如果没有登录，跳到登录页面
            else
            {
                if (Page.User.Identity.Name == "")
                    Response.Redirect(FormsAuthentication.LoginUrl);
            }
        }
    }
    
}
